package com.aaa.web.service.impl.socialuserapproveimpl;

import com.aaa.entity.AppIdcardApprove;
import com.aaa.entity.AppUserinfo;
import com.aaa.entity.Employee;
import com.aaa.phone.systemconst.ISystemConst;
import com.aaa.util.EmpUtil;
import com.aaa.web.commons.Query;
import com.aaa.web.commons.Result;
import com.aaa.web.dao.socialuserapprovedao.SocialUserApproveDao;
import com.aaa.web.service.isocialapproveservice.ISocialUserApproveService;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description:社会后台管理业务实现层
* @author: 王林林
* @create: 2018/12/26 20:51
**/
@Service
public class SocialUserApproveServiceImpl implements ISocialUserApproveService {

    @Autowired
    private SocialUserApproveDao dao;
    /**获取所有社会用户或根据手机号查询社会用户*/
    @Override
    public Map getAllSocialUser(Query query,AppUserinfo appUserinfo) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<Object, Object> map = new HashMap<>();
        List<Map> list= dao.getAllSocialUser(appUserinfo);
        map.put("data",list);
        map.put("count",dao.getAllSocialUserCount(appUserinfo));
        map.put("code",ISystemConst.ZERO);
        map.put("msg","");
        return map;
    }

    /**获取所有提交认证的社会用户*/
    @Override
    public Map getAllSocialUserWhichApprove(Query query,AppIdcardApprove idcardApprove) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<Object, Object> map = new HashMap<>();
        List<Map> list= dao.getAllSocialUserWhichApprove(idcardApprove);
        map.put("data",list);
        map.put("count",dao.getAllSocialUserWhichApproveCount(idcardApprove));
        map.put("code",ISystemConst.ZERO);
        map.put("msg","");
        return map;
    }

    /**更改两个表的状态信息和加入员工id*/
    @Transactional
    @Override
    public Result socialapprovePass(String telephone) {
        AppIdcardApprove idcardApprove = new AppIdcardApprove();
        Employee emp = EmpUtil.getEmp();
        Integer employeeid = emp.getEmployeeid();
        idcardApprove.setEmployeeid(employeeid+"");
        idcardApprove.setTelephone(telephone);
        /*根据手机号更改app_userinfo表信息*/
        int i=dao.updateUserInfo(telephone);
        /*根据手机号更改app_idcard_approve表信息*/
         int a=dao.updateIdApprove(idcardApprove);
        Result result = new Result();
        if(i> ISystemConst.ZERO){
            result.setCode(i);
        }else{
            result.setCode(i);
        }
        return result;
    }

    /**根据手机号更改两个表的状态信息*/
    @Transactional
    @Override
    public Result delSocialapprove(String telephone) {
        /*根据手机号更改app_userinfo表信息*/
         int i=dao.delUserInfo(telephone);
        /*根据手机号更改app_idcard_approve表信息*/
         int a=dao.delIdApprove(telephone);
        Result result = new Result();
        if(i>ISystemConst.ZERO){
            result.setCode(i);
        }else{
            result.setCode(i);
        }
        return result;
    }
}
